<#assign pojo=oneToManyPojo.getOne()>
<#assign many=oneToManyPojo.getMany()>
<#assign ones=oneToManyPojo.getOnes()>
<#assign module=oneToManyPojo.getModule()>
<#assign fields=pojo.getFilterdPojoFields()>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
<#assign declarationNameFirstLetterLower = pojo.importType(pojo.getDeclarationNameFirstLetterLower())>
<#assign realPackageAndClassPath = "${pojo.getRealPackageAndClassPath()}">
<#assign masterid = pojo.getDeclarationNameFirstLetterLower()+"Id">
import React from "react";
import {Link, routerRedux} from "dva/router";
import {Modal} from "antd";

<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign childdeclarationNameFirstLetterLower = child.importType(child.getDeclarationNameFirstLetterLower())>
<#if child.getRelation() == "MANY_DEFAULT">
import ${childdeclarationName}SelectToolBar from "../components/${childdeclarationName}SelectToolBar";
</#if>
import ${childdeclarationName}List from "../components/${childdeclarationName}List";
</#foreach>

export default function get${declarationName}IndexConfig (location, dispatch, ${declarationNameFirstLetterLower}, loading){
  const {${declarationNameFirstLetterLower}DataSource, ${declarationNameFirstLetterLower}Pagination, ${declarationNameFirstLetterLower}Item, ${declarationNameFirstLetterLower}ModalVisible, modalType, ${declarationNameFirstLetterLower}Rxpand, ${declarationNameFirstLetterLower}SelectedRowKeys, ${declarationNameFirstLetterLower}SelectedRows,${declarationNameFirstLetterLower}ExpandedRowKeys,
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign childdeclarationNameFirstLetterLower = child.importType(child.getDeclarationNameFirstLetterLower())>
      ${childdeclarationNameFirstLetterLower}Item,${childdeclarationNameFirstLetterLower}Visible, ${childdeclarationNameFirstLetterLower}SelectedRowKeys, ${childdeclarationNameFirstLetterLower}SelectedRows,${childdeclarationNameFirstLetterLower}EditVisible, ${childdeclarationNameFirstLetterLower}ModalType,
      ${childdeclarationNameFirstLetterLower}SelectVisible,
</#foreach>
       } = ${declarationNameFirstLetterLower}
  const { pageSize } = ${declarationNameFirstLetterLower}Pagination
  const on${declarationName}RowEditItem = function (item) {
    dispatch({
      type: '${declarationNameFirstLetterLower}/showModal',
      payload: {
        modalType: 'update',
        ${declarationNameFirstLetterLower}Item: item
      }
    })
  }
 const on${declarationName}RowDeleteItem = function (ids) {
    confirm({
      title: 'Are you sure delete this record?',
      onOk () {
        dispatch({
          type: '${declarationNameFirstLetterLower}/delete',
          payload: ids
        })
      }
    })
  }
  const ${declarationNameFirstLetterLower}FilterProps = {
    expand:${declarationNameFirstLetterLower}Rxpand,
    filter: {
      ...location.query,
    },
    onFilterChange (value) {
      dispatch(routerRedux.push({
        pathname: location.pathname,
        query: {
          ...value,
          pageIndex: 1,
          pageSize,
        },
      }))
    },
    onSearch (fieldsValue) {
      fieldsValue.keyword.length ? dispatch(routerRedux.push({
        pathname: '/${declarationNameFirstLetterLower}',
        query: {
          field: fieldsValue.field,
          keyword: fieldsValue.keyword,
        },
      })) : dispatch(routerRedux.push({
        pathname: '/${declarationNameFirstLetterLower}',
      }))
    },
    switchExpand () {
      dispatch({type: '${declarationNameFirstLetterLower}/switchExpand'})
    },
  }
  const ${declarationNameFirstLetterLower}ToolBarProps = {
    on${declarationName}AddItem () {
      dispatch({
        type: '${declarationNameFirstLetterLower}/showModal',
        payload: {
          modalType: 'create',
        },
      })
    },
    on${declarationName}EditItem () {
      if(1!==${declarationNameFirstLetterLower}SelectedRows.length){
        const modal = Modal.error({
          title: '错误的选择数量',
          content: '请选择且只选择一条并编辑',
        });
        setTimeout(() => modal.destroy(), 7000);
      }else{
        let item=${declarationNameFirstLetterLower}SelectedRows[0]
        on${declarationName}RowEditItem(item)
      }
    },
    on${declarationName}DeleteItem () {
      if(${declarationNameFirstLetterLower}SelectedRowKeys.length<=0){
        const modal = Modal.error({
          title: '错误的选择数量',
          content: '请选择需要删除的数据',
        });
        setTimeout(() => modal.destroy(), 7000);
      }else{
        on${declarationName}RowDeleteItem(${declarationNameFirstLetterLower}SelectedRowKeys)
      }
    },
  }
  const ${declarationNameFirstLetterLower}ListProps = {
    on${declarationName}RowEditItem:on${declarationName}RowEditItem,
    on${declarationName}RowDeleteItem:on${declarationName}RowDeleteItem,
    dataSource: ${declarationNameFirstLetterLower}DataSource,
    loading: loading.effects['${declarationNameFirstLetterLower}/query'],
    pagination: ${declarationNameFirstLetterLower}Pagination,
    location,
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname: pathname,
        query: {
          ...query,
          pageIndex: page.current,
          pageSize: page.pageSize
        }
      }))
    },
    rowSelection: {
      ${declarationNameFirstLetterLower}SelectedRowKeys,
      onChange: (keys,rows) => {
        dispatch({
          type: '${declarationNameFirstLetterLower}/updateState',
          payload: {
            ${declarationNameFirstLetterLower}SelectedRowKeys: keys,
            ${declarationNameFirstLetterLower}SelectedRows: rows,
          },
        })
      },
    },
    expandedRowRender(){
    return (
          <div>
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign childdeclarationNameFirstLetterLower = child.importType(child.getDeclarationNameFirstLetterLower())>
<#if child.getRelation() == "MANY_DEFAULT">
            <${childdeclarationName}SelectToolBar {...${childdeclarationNameFirstLetterLower}ToolBarProps} />
            <${childdeclarationName}List {...${childdeclarationNameFirstLetterLower}ListProps} />
</#if>
</#foreach>
          </div>
        )
    },
    expandedRowKeys:${declarationNameFirstLetterLower}ExpandedRowKeys,
    onExpand: function (expanded, record) {
      if (expanded) {
        dispatch({
          type: '${declarationNameFirstLetterLower}/updateState',
          payload: {
            ${declarationNameFirstLetterLower}ExpandedRowKeys: [record.id],
            ${declarationNameFirstLetterLower}Item: record,
          },
        })
      } else {
        dispatch({
          type: '${declarationNameFirstLetterLower}/updateState',
          payload: {
            ${declarationNameFirstLetterLower}ExpandedRowKeys: [],
            ${declarationNameFirstLetterLower}s: [],
          },
        })
      }
    },
    columns:[
<#assign fields=pojo.getFilterdPojoFields()>
<#foreach field in fields>
    <#if field.getIsSampleField()>
      {
        title: '<#if field.getComment()?exists>${field.getComment()}<#else>${field.getName()}</#if>',
        dataIndex: '${field.getName()}',
        key: '${field.getName()}',
      },
    </#if>
</#foreach>
      {
        title: 'Operation',
        key: 'operation',
        width: 100,
        render: (text, record) => {
          return <div>
            <Link onClick={e => on${declarationName}RowEditItem(record)}>edit</Link>
            <span className="ant-divider"/>
            <Link onClick={e => on${declarationName}RowDeleteItem([record.id])}>remove</Link>
          </div>
        },
      },
  ]
  }
  const ${declarationNameFirstLetterLower}ModalProps = {
    item: modalType == 'create' ? {} : ${declarationNameFirstLetterLower}Item,
    visible: ${declarationNameFirstLetterLower}ModalVisible,
    maskClosable: false,
    key:'${declarationNameFirstLetterLower}'+${declarationNameFirstLetterLower}Item.id,
    confirmLoading: loading.effects['${declarationNameFirstLetterLower}/update'],
    title: `${r"${"}modalType === 'create' ? 'Create ${declarationName}' : 'Update ${declarationName}'}`,
    wrapClassName: 'vertical-center-modal',
    onOk (data) {
      dispatch({
        type: `${declarationNameFirstLetterLower}/${r"${modalType}"}`,
        payload: data,
      })
    },
    onCancel () {
      dispatch({
        type: '${declarationNameFirstLetterLower}/hideModal'
      })
    },
  }
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign childdeclarationNameFirstLetterLower = child.importType(child.getDeclarationNameFirstLetterLower())>
  const ${childdeclarationNameFirstLetterLower}ListProps = {
    dataSource: ${declarationNameFirstLetterLower}Item.${childdeclarationNameFirstLetterLower}s,
    rowSelection: {
      ${declarationNameFirstLetterLower}SelectedRowKeys: ${childdeclarationNameFirstLetterLower}SelectedRowKeys,
      onChange: (keys, rows) => {
        dispatch({
          type: '${declarationNameFirstLetterLower}/updateState',
          payload: {
            ${childdeclarationNameFirstLetterLower}SelectedRowKeys: keys,
            ${childdeclarationNameFirstLetterLower}SelectedRows: rows,
          },
        })
      }
    },
    columns: [
      {
        title: 'outPutRoot',
        dataIndex: 'outPutRoot',
        key: 'outPutRoot',
      },
      {
        title: '${childdeclarationNameFirstLetterLower}Content',
        dataIndex: '${childdeclarationNameFirstLetterLower}Content',
        key: '${childdeclarationNameFirstLetterLower}Content',
      },
      {
        title: 'name',
        dataIndex: 'name',
        key: 'name',
      },
      {
        title: 'des',
        dataIndex: 'des',
        key: 'des',
      },
      {
        title: 'Operation',
        key: 'operation',
        width: 100,
        render: (text, record) => {
          return <div>
            <Link onClick={e => on${childdeclarationName}RowEditItem(record)}>edit</Link>
            <span className="ant-divider" />
            <Link onClick={e => on${childdeclarationName}RowDeleteItem([record.id])}>remove</Link>
          </div>
        },
      },
    ]
  }
  const on${childdeclarationName}RowEditItem = function (item) {
    dispatch({
      type: '${declarationNameFirstLetterLower}/show${childdeclarationName}EditModal',
      payload: {
        ${childdeclarationNameFirstLetterLower}ModalType: 'update',
        ${childdeclarationNameFirstLetterLower}Item: item
      }
    })
  }
  const on${childdeclarationName}RowDeleteItem = function (ids) {
    confirm({
      title: 'Are you sure delete this record?',
      onOk () {
        dispatch({
          type: '${declarationNameFirstLetterLower}/delete${childdeclarationName}',
          payload: ids
        })
      }
    })
  }
  const ${childdeclarationNameFirstLetterLower}ModalProps = {
    item: ${childdeclarationNameFirstLetterLower}ModalType == 'create' ? {} : ${childdeclarationNameFirstLetterLower}Item,
    visible: ${childdeclarationNameFirstLetterLower}EditVisible,
    maskClosable: false,
    key: '${childdeclarationNameFirstLetterLower}'+${childdeclarationNameFirstLetterLower}Item.id,
    onOk (data) {
      dispatch({
        type: `${declarationNameFirstLetterLower}/${r"$"}{${childdeclarationNameFirstLetterLower}ModalType}${childdeclarationName}`,
        payload: data,
      })
    },
    onCancel () {
      dispatch({
        type: '${declarationNameFirstLetterLower}/hide${childdeclarationName}EditModal'
      })
    },
  }
<#if child.getRelation() == "MANY_EMBED">
  const ${childdeclarationNameFirstLetterLower}ToolBarProps = {
    on${childdeclarationName}AddItem () {
      dispatch({
        type: '${declarationNameFirstLetterLower}/show${childdeclarationName}EditModal',
        payload: {
          ${childdeclarationNameFirstLetterLower}ModalType: 'create',
        },
      })
    },
    on${childdeclarationName}EditItem () {
      if (1 !== ${childdeclarationNameFirstLetterLower}SelectedRowKeys.length) {
        const modal = Modal.error({
          title: '错误的选择数量',
          content: '请选择且只选择一条并编辑',
        });
        setTimeout(() => modal.destroy(), 7000);
      } else {
        let item = ${childdeclarationNameFirstLetterLower}SelectedRows[0]
        on${childdeclarationName}RowEditItem(item)
      }
    },
    on${childdeclarationName}DeleteItem () {
      if (${childdeclarationNameFirstLetterLower}SelectedRowKeys.length <= 0) {
        const modal = Modal.error({
          title: '错误的选择数量',
          content: '请选择需要删除的数据',
        });
        setTimeout(() => modal.destroy(), 7000);
      } else {
        on${childdeclarationName}RowDeleteItem(${childdeclarationNameFirstLetterLower}SelectedRowKeys)
      }
    },
  }
</#if>
<#if child.getRelation() == "MANY_DEFAULT">
  const ${childdeclarationNameFirstLetterLower}ToolBarProps = {
    on${childdeclarationName}AddItem () {
      dispatch({
        type: '${declarationNameFirstLetterLower}/updateState',
        payload: {
          ${childdeclarationNameFirstLetterLower}SelectVisible: true,
        },
      })
    },
    on${childdeclarationName}DeleteItem () {
      if (architectureSelectedRowKeys.length <= 0) {
        const modal = Modal.error({
          title: '错误的选择数量',
          content: '请选择需要删除的数据',
        });
        setTimeout(() => modal.destroy(), 7000);
      } else {
        onArchitectureRowDeleteItem(architectureSelectedRowKeys)
      }
    },
  }
  const on${childdeclarationName}Selected=function (keys) {
    dispatch({
      type: '${declarationNameFirstLetterLower}/updateState',
      payload: {
        ${childdeclarationNameFirstLetterLower}SelectVisible: false,
      },
    })
  }
  const on${childdeclarationName}SelectedCancel=function () {
    dispatch({
      type: '${declarationNameFirstLetterLower}/updateState',
      payload: {
        ${childdeclarationNameFirstLetterLower}SelectVisible: false,
      },
    })
  }
</#if>
</#foreach>

  return {
    ${declarationNameFirstLetterLower}FilterProps,
    ${declarationNameFirstLetterLower}ToolBarProps,
    ${declarationNameFirstLetterLower}ListProps,
    ${declarationNameFirstLetterLower}ModalProps,
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
<#assign childdeclarationNameFirstLetterLower = child.importType(child.getDeclarationNameFirstLetterLower())>
    ${childdeclarationNameFirstLetterLower}ListProps,
    ${childdeclarationNameFirstLetterLower}ToolBarProps,
    ${childdeclarationNameFirstLetterLower}ModalProps,
    ${childdeclarationNameFirstLetterLower}SelectVisible,
<#if child.getRelation() == "MANY_DEFAULT">
    on${childdeclarationName}Selected,
    on${childdeclarationName}SelectedCancel,
</#if>
</#foreach>
  }
}